<template>
	<view class="box">
		<order-item v-for="item in list"
			:item="item"
			:userId="userId"
			:key="item.orderId"
			class="order-item"
			v-if="pageStatus == 2">
		</order-item>
			
			
		<view class="not-fond-box not-login" v-if="pageStatus == 0">
			请先<text @click="toLogin">登录</text>
		</view>
			
		<view class="not-fond-box" v-if="pageStatus == 1">
			暂无订单
		</view>
	</view>
</template>

<script>
	import orderItem from './components/order-item/order-item.vue'
	import { mapState } from 'vuex'
		
	export default {
		components: { orderItem },
		data() {
			return {
				list: []
			}
		},
		methods: {
			toLogin() {
				uni.navigateTo({
					url: '/pages/login/login'
				})
				return 
			}
		},
		computed: {
			...mapState('user', ['userId']),
			pageStatus() {				
				if (!this.userId) {
					// 未登录
					return 0
				} else if (typeof(this.list) === 'undefined' || this.list.length === 0) {
					// 没有订单
					return 1
				} else {
					// 查询订单
					return 2
				}
			}
		},
		onShow() {			
			// 查询
			this.$myRequest({
				url: '/sysOrder/' + this.userId
			}).then(res => {
				this.list = res.data.result
			})
		}
	}
</script>

<style scoped>
	.box{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 100%;
	}
	
	.order-item{
		margin-top: 30rpx;
		width: 100%;
		display: flex;
		justify-content: center;
	}

	
	.order-item:first-child{
		margin-top: 10rpx;
	}
	
	.order-item:last-child{
		margin-bottom: 20rpx;
	}
	
	.not-fond-box{
		margin-top: 50rpx;
		font-size: 15px;
		font-weight: 600;
		text-align: center;
	}
	
	.not-login text{
		color: #00B386;
	}
</style>
